/********************************************/
  // Creation History
  // --------------------------------------------------------------
  //	Company:			HTHK
  //	NAME:				CompanyOptions.java
  //    Title   :			get the Company Data into a list box
  //	FUNCTION:
  //	BY:					Jet Tao
  //	DATE:				09/12/2003
  // --------------------------------------------------------------
/*********************************************/

package tss.options;

import tss.common.Options2;
import java.util.ArrayList;
import java.sql.Connection;

import tss.company.*;

/**
 * A Class class.
 * <P>
 * @author HTHK
 */
public class CompanyOptions
  extends Options2
{

  /**
   * Constructor
   */
  public CompanyOptions() {
      this.load();
  }

  @Override
protected ArrayList createOptions(Connection con)
    throws Exception
  {
      ArrayList options = new ArrayList();
      CompanyBean Company = CompanyProcess.createBean();
      Company.setCompany_code("");
      CompanyBean[] Companys = CompanyProcess.find(con,Company);
      for (int i=0; i<Companys.length; i++)
      {
          Options2.Option option
          = new Options2.Option( Companys[i].getCompany_code(),
                                Companys[i].getCompany_code());
          options.add(i,option);
      }
      return options;
  }

  public String getDefualtOptions(String value)
  {
      StringBuffer htmlOptions = new StringBuffer();
	  for (int i=0; this.options!=null && i<this.options.size(); i++)
      {

          Option option = (Option)options.get(i);
		  boolean selected = false;
		  if (value!=null && value.length()!=0 && option.getValue().equals(value))
				selected = true;
		  else
		  {
			  if(i==0)
				  selected = true;
          }
          htmlOptions.append("   <option value=\"").append(option.getValue()).append("\"").append(selected?" selected ":" ").append(" >").append(option.getDescription()).append("</option>\n");
      }
      return htmlOptions.toString();
  }
  


}

